import 'package:flutter/material.dart';
import 'dart:convert';
import '../routes/routes.dart';
import 'package:fluro/fluro.dart';

class Launch extends StatefulWidget{

  @override
  State<StatefulWidget> createState() {

    // TODO: implement createState
    return _Launch();
  }

}
class _Launch extends State<Launch>{

//  GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final _formKey = GlobalKey<FormState>();
  String _password;
  double _visible =0.0;
  void _onSubmit(){
    var state = _formKey.currentState;
    state.validate();
    state.save();
    showDialog(context: context,builder:(context){
      return  new AlertDialog(content: Text("密码:$_password"),);
    } );

    var json = jsonEncode(Utf8Encoder().convert('来自启动页面'));
//    Navigator.push(context, MaterialPageRoute(builder: (context)=>Home()));
       Routes.router.navigateTo(context, '${Routes.homeRoute}?message=$json',
       transition: TransitionType.inFromRight
      ).then((value){
        print("回传的值$value");
       });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Form(
        onChanged: (){setState(() => _visible = 1.0);},
        key: _formKey,
        child:Container(
          child: Column(
            children: <Widget>[
             Padding(
                padding:EdgeInsets.fromLTRB(0, 100, 0, 0),
                child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Image.network("https://img01.sogoucdn.com/net/a/04/link?url=https%3A%2F%2Fi01picsos."
                      "sogoucdn.com%2Faf2f5bb76c4a789a&appid=122",
                  fit:BoxFit.fill ,
                  width: 200,
                  height: 150,)
                ],
              ),
            ),

            Padding(
              padding: EdgeInsets.symmetric(vertical: 0,horizontal: 20),
              child: Row(
                children: <Widget>[
                  Expanded(
                  child: TextFormField(
                      maxLength: 32, //文本长度
                      obscureText: true,
                      autofocus:true,
                    onSaved:(value)=> this._password = value ,
                    decoration: InputDecoration(

                      prefixText: "  密码     ",
                      prefixStyle:TextStyle(fontSize: 20),
                      hintText: "请填写QQ密码",
                      hintStyle: TextStyle(fontSize: 20),
                      suffixIcon:Opacity(
                            opacity:_visible,
                            child: FlatButton(
                                        onPressed:(){
                                          setState(() {
                                            _visible = 0.0;
                                             });
                                          _formKey.currentState.reset();
                                          },
                                       child:Icon(Icons.close),
                                      ),
                      )
                    ),
                      textAlign: TextAlign.start,
                      validator:(value){
                        return (value == null  || value.isEmpty)?"请输入正确密码":null;
                      }
                  ),
            )
              ],
            ),
          ),
              MaterialButton(
//                padding: EdgeInsets.symmetric(horizontal: 150),
               minWidth: 350,
                color: Colors.greenAccent,
                child: Text("登录"),
                onPressed: _onSubmit,
             ),
        ],
      ),
      )
    ),
    );
  }



}